home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Draw / Sources / ShpTrakr.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  8.4 KB  |  317 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                ShpTrakr.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef SHPTRAKR_H
  15. #include "ShpTrakr.h"
  16. #endif
  17.  
  18. #ifndef UTILS_H
  19. #include "Utils.h"
  20. #endif
  21.  
  22. #ifndef BASESHP_H
  23. #include "BaseShp.h"
  24. #endif
  25.  
  26. #ifndef BOUNDSHP_H
  27. #include "BoundShp.h"
  28. #endif
  29.  
  30. #ifndef LINESHP_H
  31. #include "LineShp.h"
  32. #endif
  33.  
  34. #ifndef OVALSHP_H
  35. #include "OvalShp.h"
  36. #endif
  37.  
  38. #ifndef RECTSHP_H
  39. #include "RectShp.h"
  40. #endif
  41.  
  42. #ifndef RRECTSHP_H
  43. #include "RRectShp.h"
  44. #endif
  45.  
  46. #ifndef TEXTSHP_H
  47. #include "TextShp.h"
  48. #endif
  49.  
  50. #ifndef DRAWVIEW_H
  51. #include "DrawView.h"
  52. #endif
  53.  
  54. // ----- Part Layer -----
  55.  
  56. #ifndef FWCONTXT_H
  57. #include "FWContxt.h"
  58. #endif
  59.  
  60. #ifndef FWSCROLR_H
  61. #include "FWScrolr.h"
  62. #endif
  63.  
  64. #ifndef FWUTIL_H
  65. #include "FWUtil.h"
  66. #endif
  67.  
  68. #ifndef FWVIEW_H
  69. #include "FWView.h"
  70. #endif
  71.  
  72. #ifndef FWFRAME_H
  73. #include "FWFrame.h"
  74. #endif
  75.  
  76. // ----- OS Layer -----
  77.  
  78. #ifndef FWRECSHP_H
  79. #include "FWRecShp.h"
  80. #endif
  81.  
  82. //========================================================================================
  83. // Runtime Information
  84. //========================================================================================
  85.  
  86. #ifdef FW_BUILD_MAC
  87. #pragma segment odfdraw
  88. #endif
  89.  
  90. //========================================================================================
  91. //    class CShapeTracker
  92. //========================================================================================
  93.  
  94. //----------------------------------------------------------------------------------------
  95. //    CShapeTracker::CShapeTracker
  96. //----------------------------------------------------------------------------------------
  97.  
  98. CShapeTracker::CShapeTracker(Environment* ev, FW_CView* view, ODFacet* facet, CBaseShape* theShape, FW_Boolean gridOn) :
  99.     FW_CTracker(ev, view, facet),
  100.     fShape(theShape),
  101.     fErase(FALSE),
  102.     fGridOn(gridOn),
  103.     fScroller(view->GetFrame(ev)->GetScroller(ev))
  104. {
  105. }
  106.  
  107. //----------------------------------------------------------------------------------------
  108. //    CShapeTracker::~CShapeTracker
  109. //----------------------------------------------------------------------------------------
  110.  
  111. CShapeTracker::~CShapeTracker()
  112. {
  113. }
  114.  
  115. //----------------------------------------------------------------------------------------
  116. //    CShapeTracker::BeginTracking
  117. //----------------------------------------------------------------------------------------
  118.  
  119. FW_CPoint CShapeTracker::BeginTracking(Environment* ev, 
  120.                                     const FW_CPoint& anchorPoint)
  121. {
  122.     FW_CPoint point(anchorPoint);
  123.     ForceToGrid(ev, point);
  124.     
  125.     fScroller->InitializeAutoScroll(ev);
  126.     
  127.     return point;
  128. }
  129.  
  130. //----------------------------------------------------------------------------------------
  131. //    CShapeTracker::ContinueTracking
  132. //----------------------------------------------------------------------------------------
  133.  
  134. FW_CPoint CShapeTracker::ContinueTracking(Environment* ev,
  135.                                         const FW_CPoint& anchorPoint, 
  136.                                         const FW_CPoint& previousPoint, 
  137.                                         const FW_CPoint& currentPoint)
  138. {
  139.     FW_CPoint curLoc(currentPoint);
  140.     
  141.     ForceToGrid(ev, curLoc);
  142.     
  143.     if (previousPoint != curLoc)
  144.     {
  145.         FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  146.         
  147.         if (fErase)
  148.             fShape->TrackFeedback(ev, GetFacet(ev), vc, anchorPoint, previousPoint, TRUE);
  149.  
  150.         fScroller->AutoScroll(ev, currentPoint, &vc);
  151.  
  152.         fShape->TrackFeedback(ev, GetFacet(ev), vc, anchorPoint, curLoc, FALSE);
  153.         
  154.         fErase = TRUE;
  155.     }
  156.     
  157.     return curLoc;
  158. }
  159.  
  160. //----------------------------------------------------------------------------------------
  161. //    CShapeTracker::EndTracking
  162. //----------------------------------------------------------------------------------------
  163.  
  164. FW_Boolean CShapeTracker::EndTracking(Environment* ev,
  165.                                     const FW_CPoint& anchorPoint, 
  166.                                     const FW_CPoint& lastPoint)
  167. {
  168.     if (fErase)
  169.     {
  170.         FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  171.         
  172.         fShape->TrackFeedback(ev, GetFacet(ev), vc, anchorPoint, lastPoint, TRUE);
  173.     }
  174.     
  175.     return anchorPoint != lastPoint;
  176. }
  177.  
  178. //----------------------------------------------------------------------------------------
  179. //    CShapeTracker::ForceToGrid
  180. //----------------------------------------------------------------------------------------
  181.  
  182. void CShapeTracker::ForceToGrid(Environment* ev, FW_CPoint& point)
  183. {
  184.     if (fGridOn)
  185.     {
  186.         point.x = FW_IntToFixed((FW_FixedToInt(point.x) + 5) / 8 * 8);
  187.         point.y = FW_IntToFixed((FW_FixedToInt(point.y) + 5) / 8 * 8);
  188.     }
  189. }
  190.  
  191. //========================================================================================
  192. //    class CResizeTracker
  193. //========================================================================================
  194.  
  195. //----------------------------------------------------------------------------------------
  196. //    CResizeTracker::CResizeTracker
  197. //----------------------------------------------------------------------------------------
  198.  
  199. CResizeTracker::CResizeTracker(Environment* ev,
  200.                                 FW_CView* view, ODFacet* facet, 
  201.                                 CBaseShape* theShape, short whichHandle,
  202.                                 const FW_CInk& resizeInk, const FW_CStyle& resizeStyle,
  203.                                 FW_Boolean gridOn) :
  204.     FW_CTracker(ev, view, facet),
  205.     fShape(theShape),
  206.     fWhichHandle(whichHandle),
  207.     fResizeInk(resizeInk),
  208.     fResizeStyle(resizeStyle),
  209.     fErase(FALSE),
  210.     fGridOn(gridOn),
  211.     fScroller(view->GetFrame(ev)->GetScroller(ev))
  212. {
  213. }
  214.  
  215. //----------------------------------------------------------------------------------------
  216. //    CResizeTracker::~CResizeTracker
  217. //----------------------------------------------------------------------------------------
  218.  
  219. CResizeTracker::~CResizeTracker()
  220. {
  221. }
  222.  
  223. //----------------------------------------------------------------------------------------
  224. //    CResizeTracker::BeginTracking
  225. //----------------------------------------------------------------------------------------
  226.  
  227. FW_CPoint CResizeTracker::BeginTracking(Environment* ev, const FW_CPoint& anchorPoint)
  228. {
  229.     FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  230.     
  231.     FW_CPoint handleSize = vc.DeviceToLogical(2, 2);
  232.     
  233.     FW_CRectShape handle(FW_kZeroRect, FW_kFill);
  234.     handle.SetInk(FW_kInvertInk);
  235.     fShape->CalcHandle(fWhichHandle, &handle, handleSize);
  236.     handle.Render(vc);    // redraw the handle
  237.  
  238.     FW_CPoint point(anchorPoint);
  239.     ForceToGrid(ev, point);
  240.     
  241.     FW_CPoint handleCenter;
  242.     fShape->GetHandleCenter(fWhichHandle, handleCenter);
  243.     fDelta = point - handleCenter;
  244.  
  245.     fScroller->InitializeAutoScroll(ev);
  246.     
  247.     return handleCenter;
  248. }
  249.  
  250. //----------------------------------------------------------------------------------------
  251. //    CResizeTracker::ContinueTracking
  252. //----------------------------------------------------------------------------------------
  253.  
  254. FW_CPoint CResizeTracker::ContinueTracking(Environment* ev,
  255.                                             const FW_CPoint& anchorPoint, 
  256.                                             const FW_CPoint& previousPoint, 
  257.                                             const FW_CPoint& currentPoint)
  258. {
  259. FW_UNUSED(anchorPoint);
  260.  
  261.     // ----- Adjust for the size of the handle
  262.     FW_CPoint curLoc(currentPoint - fDelta);        
  263.     ForceToGrid(ev, curLoc);
  264.  
  265.     if (previousPoint != curLoc)
  266.     {
  267.         FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  268.     
  269.         if (fErase)
  270.             fShape->ResizeFeedback(vc, fResizeInk, fResizeStyle, fWhichHandle, previousPoint);        // erase
  271.                 
  272.         fScroller->AutoScroll(ev, currentPoint, &vc);
  273.  
  274.         fShape->ResizeFeedback(vc, fResizeInk, fResizeStyle, fWhichHandle, curLoc);            // draw
  275.         
  276.         fErase = TRUE;                
  277.     }
  278.     
  279.     return curLoc;
  280. }
  281.  
  282. //----------------------------------------------------------------------------------------
  283. //    CResizeTracker::EndTracking
  284. //----------------------------------------------------------------------------------------
  285.  
  286. FW_Boolean CResizeTracker::EndTracking(Environment* ev,
  287.                                     const FW_CPoint& anchorPoint, 
  288.                                     const FW_CPoint& lastPoint)
  289. {
  290. FW_UNUSED(anchorPoint);
  291.  
  292.     fLastLocation = lastPoint - fDelta;
  293.     ForceToGrid(ev, fLastLocation);
  294.     
  295.     if (fErase)
  296.     {
  297.         FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
  298.     
  299.         fShape->ResizeFeedback(vc, fResizeInk, fResizeStyle, fWhichHandle, fLastLocation);
  300.     }
  301.     
  302.     return anchorPoint != lastPoint;
  303. }
  304.  
  305. //----------------------------------------------------------------------------------------
  306. //    CResizeTracker::ForceToGrid
  307. //----------------------------------------------------------------------------------------
  308.  
  309. void CResizeTracker::ForceToGrid(Environment* ev, FW_CPoint& point)
  310. {
  311.     if (fGridOn)
  312.     {
  313.         point.x = FW_IntToFixed((FW_FixedToInt(point.x) + 5) / 8 * 8);
  314.         point.y = FW_IntToFixed((FW_FixedToInt(point.y) + 5) / 8 * 8);
  315.     }
  316. }
  317.